package com.compass.mobile.presenters

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.leanback.widget.Presenter
import com.compass.mobile.R
import com.compass.mobile.models.TicketModel
import getColorFromResource

/**
 * Description： 预约时段
 * Date:2024/6/25 22:54
 */
class NumberSegmentPresenter : Presenter() {

    override fun onCreateViewHolder(viewGroup: ViewGroup): ViewHolder {
        val view =
            LayoutInflater.from(viewGroup.context).inflate(R.layout.item_appointment_number, viewGroup, false)
        return ViewHolder(view)
    }

    override fun onBindViewHolder(viewHolder: Presenter.ViewHolder, item: Any) {
        if (item is TicketModel) {
            val vh = viewHolder as ViewHolder
            vh.tvTitle.text = item.time
            if (item.flagStatus=="1"){
                vh.tvFlagStatus.text="可预约"
                vh.tvFlagStatus.setTextColor(getColorFromResource(R.color.chartreuse))
            }else{
                vh.tvFlagStatus.setTextColor(getColorFromResource(R.color.main_title))
                vh.tvFlagStatus.text="已约满"
            }




        }
    }

    override fun onUnbindViewHolder(viewHolder: Presenter.ViewHolder) {}
    class ViewHolder(view: View) : Presenter.ViewHolder(view) {
        var tvTitle: TextView
        var tvFlagStatus: TextView

        init {
            tvTitle = view.findViewById(R.id.tv_title)
            tvFlagStatus = view.findViewById(R.id.tvFlagStatus)

        }
    }
}